package com.cn.dream_order_server.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.cn.dream_order_server.pojo.OrderShopping;
import com.cn.dream_order_server.service.OrderCartService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class OrderCartController {

    @Autowired
    private OrderCartService orderCartService;

    //根据用户获取全部的购物车信息
    @GetMapping("/wlcGetListCart")
    public String wlcGetListCart(HttpServletRequest request , Map map, HttpSession session){
        String userUser = (String) session.getAttribute("userStaff");
        System.out.println(userUser);


        Map<String, Object> objectMap = orderCartService.getOrederShoppingListByUserId("1");
        map.put("orderShoppingList",objectMap.get("orderShoppingList"));
        map.put("cartTotal",objectMap.get("cartTotal"));
        return "cart";
    }


    @RequestMapping("/updateShoppingNum")
    @ResponseBody
    public Object updateShoppingNum(String id,Integer num){
        orderCartService.updateOrderShoppingByShoppingId(id,num);
        return "OK";
    }


    @RequestMapping(value = "wlcDeleteOrderShoppongByShoppingId")
    @ResponseBody
    public Object wlcDeleteOrderShoppongByShoppingId(String cartId){
        Integer integer = orderCartService.deleteOrderShoppingByShoppingId(cartId);
        boolean flag = false;
        if (integer.equals(1)){
            flag =  true;
        }
        return JSONUtils.toJSONString(flag);
    }
}
